import Banner from "../Banner";
import { 头盔, 手枪, 防弹衣, 突击步枪, 冲锋枪, 射手步枪, 栓动步枪, 轻机枪, 霰弹枪, 卡宾枪, 投掷物, 子弹, 药品, 食物, } from "../Datas/Data";
import { Constant, ItemType } from "../Framework/Const/Constant";
import AudioManager from "../Framework/Managers/AudioManager";
import { DataManager } from "../Framework/Managers/DataManager";
import { PoolManager } from "../Framework/Managers/PoolManager";
import { UIManager } from "../Framework/Managers/UIManager";
import NodeUtil from "../Framework/Utils/NodeUtil";
import Item from "./Item";
import SkinItem from "./SkinItem";

const { ccclass, property } = cc._decorator;

@ccclass
export default class SkinShopPanel extends cc.Component {
    ItemContent: cc.Node = null;

    items: cc.Node[] = [];

    protected onLoad(): void {
        this.ItemContent = NodeUtil.GetNode("ItemContent", this.node);
    }

    Show() {
        Banner.Instance.ShowCustomAd();
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        this.RefreshItems();
    }

    RefreshItems() {
        this.items.forEach(e => PoolManager.PutNode(e));

        for (let i = 0; i < DataManager.JunXuItems.length; i++) {
            const data = DataManager.JunXuItems[i];
            PoolManager.GetNode("Prefabs/UI/SkinItem", this.ItemContent).then(e => {
                let item = e.getComponent(SkinItem);
                this.items.push(e);
                switch (ItemType[`${data.Type}`]) {
                    case ItemType.头盔: item.头盔(data as 头盔); break;
                    case ItemType.防弹衣: item.防弹衣(data as 防弹衣); break;
                    case ItemType.手枪: item.手枪(data as 手枪); break;
                    case ItemType.突击步枪: item.突击步枪(data as 突击步枪); break;
                    case ItemType.冲锋枪: item.冲锋枪(data as 冲锋枪); break;
                    case ItemType.射手步枪: item.射手步枪(data as 射手步枪); break;
                    case ItemType.栓动步枪: item.栓动步枪(data as 栓动步枪); break;
                    case ItemType.轻机枪: item.轻机枪(data as 轻机枪); break;
                    case ItemType.霰弹枪: item.霰弹枪(data as 霰弹枪); break;
                    case ItemType.卡宾枪: item.卡宾枪(data as 卡宾枪); break;
                    case ItemType.投掷物: item.投掷物(data as 投掷物); break;
                    case ItemType.子弹: item.子弹(data as 子弹); break;
                    case ItemType.药品: item.药品(data as 药品); break;
                    case ItemType.食物: item.食物(data as 食物); break;
                }
            })
        }
    }

    OnReturnButtonClick() {
        AudioManager.PlayAudio(Constant.Audio.ButtonClick);
        UIManager.Instance.HidePanel(Constant.Panel.SkinShopPanel);
    }
}